﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Nhom14_HTTTHD_BuyMe
{
    public partial class register : System.Web.UI.Page
    {
        protected int RandomNumber(int min, int max)
        {
            Random random = new Random();
            return random.Next(min, max);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            Info_Capcha.Text = RandomNumber(100000, 999999).ToString();
        }

        protected void Info_submit_Click(object sender, EventArgs e)
        {
            if (Info_Password.Text != Info_CPassword.Text) { Label2.Text = "Mật khẩu và xác nhận mật khẩu không giống nhau!"; } else {
                using (websitebrokenEntities context = new websitebrokenEntities())
                {
                    //public int Register(string username, string password, string email, string firstname, string lastname, string tel, string fax, string company, string website)
                    string par1 = Info_Username.Text;
                    string par2 = Info_Password.Text;
                    string par3 = Info_email.Text;
                    string par4 = Info_Firstname.Text;
                    string par5 = Info_Lastname.Text;
                    string par6 = Info_Tel.Text;
                    string par7 = Info_Fax.Text;
                    string par8 = Info_Company.Text;
                    string par9 = Info_Website.Text;

                    string address = "http://localhost:49744/WebService1.asmx";
                    string function = "Register";

                    int res = (int)WebserviceInvoker.WSInvoker.CallWebService(address, "WebService1", function, new object[] { par1, par2, par3, par4, par5, par6, par7, par8, par9 });

                    if (res != 0)
                    {
                        Response.Redirect("Default.aspx");
                    }
                    else
                    {
                        Label2.Text = "Something is error!";
                    }     
                }
            }
        }
    }
}